package com.shycloud.mido.basic.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.shycloud.mido.basic.api.entity.BasAreas;
import com.shycloud.mido.basic.api.entity.BasCities;
import com.shycloud.mido.basic.service.BasAreasService;
import com.shycloud.mido.basic.service.BasCitiesService;
import com.shycloud.mido.basic.service.BasProvincesService;
import com.shycloud.mido.common.core.util.R;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 省份管理 前端控制器
 *
 * @author yyy
 */
@RestController
@AllArgsConstructor
@RequestMapping("/provinces")
@Api(value = "provinces", description = "省份管理模块")
public class ProvincesController {

	private final BasProvincesService basProvincesService;
	private final BasCitiesService basCitiesService;
	private final BasAreasService basAreasService;

	/**
	 * 查询省份名称列表
	 *
	 * @return 省份名称
	 */
	@GetMapping("/selProvinces")
	public R selProvinces() {
		return new R<>(basProvincesService.list());
	}

	/**
	 * 根据省份名查询城市列表
	 *
	 * @param provincesId   省份id
	 * @return 城市列表
	 */
	@GetMapping("/getCities")
	public R getCities(@RequestParam(value="provincesId") String provincesId) {
		// 查询字典表
		List<BasCities> citiesList = basCitiesService.list(Wrappers
				.<BasCities>query().lambda()
				.eq(BasCities::getProvinceid, provincesId));
		return new R<>(citiesList);
	}

	/**
	 * 根据城市名查询地区列表
	 *
	 * @param cityId   城市id
	 * @return 地区列表
	 */
	@GetMapping("/getAreas")
	public R getAreas(@RequestParam(value="cityId") String cityId) {
		// 查询字典表
		List<BasAreas> areasList = basAreasService.list(Wrappers
				.<BasAreas>query().lambda()
				.eq(BasAreas::getCityid, cityId));
		return new R<>(areasList);
	}

}
